package com.supermap.dataservice.user.dao;

import com.supermap.dataservice.util.Table;
import com.supermap.dubbo.api.user.entity.*;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;

/**
 * @author lxs
 * @Title:服务对象类型相关 数据层
 * @Description:
 * @date 2018/7/26  16:46
 */
@Mapper
public interface UserTypeDao {

    /**
     * 根据用户名查询
     */
    @Select("SELECT\n" +
            "\ta.id,\n" +
            "\tc.`id` rolecode\n" +
            "FROM\n" +
            "\t`t_user` a\n" +
            "LEFT JOIN t_user_role b ON a.id = b.userid\n" +
            "LEFT JOIN t_role c ON b.roleid = c.id\n" +
            "where a.loginname=#{username}")
    InterNetInfo getUserId(@Param("username") String username);

    /***
     * 取出新增专家id
     * */
    @Select("select id from t_expertinfo where userid=#{userId}")
    int getExpId(@Param("userId") int userId);

    /**
     * 查询对应角色表
     **/
    @Select("select count(id) from t_expertinfo where userid=#{userId}")
    int getExpertNum(@Param("userId") int userId);

    @Select("select count(1) from t_company where userid=#{userId}")
    int getCompanyNum(@Param("userId") int userId);

    @Select("select count(1) from t_cooperative where userid=#{userId}")
    int getCooperativeNum(@Param("userId") int userId);

    @Select("select count(1) from t_grower where userid=#{userId}")
    int getGrowerNum(@Param("userId") int userId);

    @Select("select count(1) from t_countryside where userid=#{userId}")
    int getCountrysideNum(@Param("userId") int userId);

    @Select("select count(1) from t_suply_point where userid=#{userId}")
    int getSuplyNum(@Param("userId") int userId);

    @Select("select count(1) from t_suply_yy where userid=#{userId}")
    int getHospitalNum(@Param("userId") int userId);

    /***
     * 获取用户角色id
     * */
    @Select("SELECT * FROM t_user_role where userid=#{userId}")
    TUserRole getUserRoleId(@Param("userId") int userId);

    /**
     * 插入专家详情
     **/
    @InsertProvider(type = userType.class, method = "insertEXPERT")
    int insertEXPERT(@Param("interNetInfo") InterNetInfo interNetInfo);

    /**
     * 专家关联表
     */
    @Insert("insert into t_expert_subject (expertid,subjectid) value(#{exSubid},#{subId})")
    int insertExSub(@Param("exSubid") int exSubid, @Param("subId") int subId);

    @Select("select count(id) from t_expert_subject where expertid=#{exSubid}")
    int getExId(@Param("exSubid") int exSubid);

    @Update("update t_expert_subject set subjectid=#{subjectid} where expertid=#{expertid}")
    int updateExSub(@Param("subjectid")int subjectid,@Param("expertid")int expertid);

    /***
     * 插入企业
     * **/
    @InsertProvider(type = userType.class, method = "insertQYYH")
    int insertQYYH(@Param("interNetInfo") InterNetInfo interNetInfo);

    /**
     * 插入合作社
     **/
    @InsertProvider(type = userType.class, method = "insertHZSYH")
    int insertHZSYH(@Param("interNetInfo") InterNetInfo interNetInfo);

    /***
     * 插入种植大户
     * */
    @InsertProvider(type = userType.class, method = "insertZZDH")
    int insertZZDH(@Param("interNetInfo") InterNetInfo interNetInfo);

    /**
     * 插入最美乡村
     */
    @InsertProvider(type = userType.class, method = "insertZMXC")
    int insertZMXC(@Param("interNetInfo") InterNetInfo interNetInfo);

    /**
     * 插入供销社
     **/
    @InsertProvider(type = userType.class, method = "insertGXS")
    int insertGXS(@Param("interNetInfo") InterNetInfo interNetInfo);

    /**
     * 插入专家医院
     **/
    @InsertProvider(type = userType.class, method = "insertZJYY")
    int insertZJYY(@Param("interNetInfo") InterNetInfo interNetInfo);

    /**
     * 更新普通用户
     **/
    @UpdateProvider(type = userType.class, method = "updatePTYHbyId")
    int updatePTYHbyId(@Param("interNetInfo") InterNetInfo interNetInfo);

    /***
     * 更新种养大户
     * **/
    @UpdateProvider(type = userType.class, method = "updateZZDHbyUserId")
    int updateZZDHbyUserId(@Param("interNetInfo") InterNetInfo interNetInfo);

    /***
     * 更新专家
     * **/
    @UpdateProvider(type = userType.class, method = "updateEXPERTbyUserId")
    int updateEXPERTbyUserId(@Param("interNetInfo") InterNetInfo interNetInfo);

    /***
     * 合作社
     * **/
    @UpdateProvider(type = userType.class, method = "updateHZSYHbyUserId")
    int updateHZSYHbyUserId(@Param("interNetInfo") InterNetInfo interNetInfo);

    /***
     * 供销社
     * */
    @UpdateProvider(type = userType.class, method = "updateGXSbyUserId")
    int updateGXSbyUserId(@Param("interNetInfo") InterNetInfo interNetInfo);

    /**
     * 最美乡村
     **/
    @UpdateProvider(type = userType.class, method = "updateZMXCbyUserId")
    int updateZMXCbyUserId(@Param("interNetInfo") InterNetInfo interNetInfo);

    /**
     * 专家医院
     **/
    @UpdateProvider(type = userType.class, method = "updateZJYYbyUserId")
    int updateZJYYbyUserId(@Param("interNetInfo") InterNetInfo interNetInfo);

    /**
     * 更新企业
     **/
    @UpdateProvider(type = userType.class, method = "updateQYYHbyUserId")
    int updateQYYHbyUserId(@Param("interNetInfo") InterNetInfo interNetInfo);

    /***
     * 获取专家类型
     * **/
    @Select("select * from t_subject where del_flg=0")
    List<TSubject> getTsubjects();

    /***
     * 查询用户信息
     * **/
    @SelectProvider(type = userType.class, method = "getInterNetInfo")
    List<InterNetInfo> getInterInfo(@Param("userId") int userId, @Param("roleCode") String roleCode);

    @Select("select * from t_role ")
    List<Role> getRoleList();

    @SelectProvider(type = userType.class, method = "getUserTypeListSQL")
    List<UserType> getUserTypeList(@Param("areaCode") String areaCode, @Param("code") String code);

    @Select("select *,v.Lat as latitude, v.Lon as longitude from t_vip v where userid=#{id} ")
    List<Vip> getVipById(@Param("id") String id);

    @Select("select id,username,mobile,address,Email,Introduction,areaCode from t_user where id=#{id} ")
    User getUserById(@Param("id") String id);

    @Select("select * from t_vip where userId=#{userId}")
    Vip getVipByUserId(@Param("userId") String userId);

    @Update("update t_vip set epath=#{epath} where userId=#{userId}")
    int updateEpathByUserId(@Param("epath") String epath, @Param("userId") String userId);

    @Update("update t_user_role set roleid=#{roleId} where userid=#{userId}")
    int updateUserRole(@Param("userId") String userId, @Param("roleId") String roleId);

    @Insert("insert into t_user_role (userid,roleid) VALUES (#{userId},#{roleId})")
    int insertUserRole(@Param("userId") String userId, @Param("roleId") String roleId);

    @Select("select count(*) c from t_user_role where userid=#{userId} and roleid=#{roleId}")
    int existUserRole(@Param("userId") String userId, @Param("roleId") String roleId);

    @Delete("delete from t_user_role where userid=#{userId}")
    int deleteUserRole(@Param("userId") String userId);

    @Insert("insert into t_vip (userId,epath) VALUES (#{userId},#{epath})")
    int insertVip(@Param("userId") String userId, @Param("epath") String epath);

    @SelectProvider(type = userType.class, method = "getExpertByAreaCodeAndSubjectIdSql")
    List<Map<String, Object>> getEXPERTListByareaCode(@Param("table") Table table, @Param("areaCode") String areaCode, @Param("subjectId") String subjectId);

    @SelectProvider(type = userType.class, method = "getExpertByAreaCodeAndSubjectIdCountSql")
    int getEXPERTCount(@Param("areaCode") String areaCode, @Param("subjectId") String subjectId);

    /**
     * 内部类 编写动态sql
     *
     * @author lxs
     */
    public class userType {
        public String getUserTypeListSQL(Map<String, Object> map) {
            String areaCode = (String) map.get("areaCode");
            String code = (String) map.get("code");

            StringBuilder stringBuilder = new StringBuilder();
            stringBuilder.append(" select t1.id,t1.username,t3.code,t1.longitude ,t1.latitude from t_user t1\n" +
                    "             INNER JOIN t_user_role t2\n" +
                    "              on t1.id=t2.userid\n" +
                    "              INNER JOIN t_role t3 \n" +
                    "              on t3.id=t2.roleid \n" +
                    "              where t1.del_flg=0  ");
            if (areaCode != null) {
                stringBuilder.append(" and t1.areaCode like concat(" + areaCode + ",'%') ");
            }

            if (code != null && code.equals("qt")) {
                stringBuilder.append(" and t1.state=-1  ");
            } else {
                stringBuilder.append(" and t1.state=0 and   t3.code='" + code + "' ");
            }

            return stringBuilder.toString();
        }

        //专家相关的数据
        public String getExpertByAreaCodeAndSubjectIdSql(Map<String, Object> map) {
            //获取分页数据
            Table table = (Table) map.get("table");
            String areaCode = (String) map.get("areaCode");
            String subjectId = (String) map.get("subjectId");
            //创建stringbuilder对象
            StringBuilder sql = new StringBuilder();
            sql.append(" select t1.id,t1.userid,t2.showName name,t2.HeadImage ,t1.unit,t2.Introduction introduction,t2.mobile telephone,\n" +
                    "\tt2.address,t1.gender,t2.longitude,t2.latitude,t6.id as subjectid,t6.name as subjectName,t3.areacode,t3.areaname  from  t_expertinfo t1\n" +
                    "\tinner join t_user t2 on t1.userid = t2.id\n" +
                    "\tinner join t_area t3 on t2.areaCode = t3.areacode\n" +
                    "\tleft join \n" +
                    "\t(select t5.expertId,t4.name,t4.id from  t_subject  t4\n" +
                    "\tinner join t_expert_subject t5 on t4.id = t5.subjectId) t6\n" +
                    "\ton t1.id = t6.expertId\n" +
                    "\twhere t1.del_flg = 0 and t2.del_flg = 0 ");
            if (areaCode != null) {
                sql.append(" and t3.`areacode` LIKE '" + areaCode + "%'");
            }
            if (subjectId != null) {
                sql.append(" and  t6.id = " + subjectId);
            }
            sql.append(" ORDER BY t1.`createtime`  desc limit " + table.getStartPoint() + "," + table.getLimit());
            return sql.toString();
        }

        public String getExpertByAreaCodeAndSubjectIdCountSql(Map<String, Object> map) {
            //获取总数数据
            String areaCode = (String) map.get("areaCode");
            String subjectId = (String) map.get("subjectId");
            //创建stringbuilder对象
            StringBuilder sql = new StringBuilder();
            sql.append(" select count(1) from  t_expertinfo t1\n" +
                    "\tinner join t_user t2 on t1.userid = t2.id\n" +
                    "\tinner join t_area t3 on t2.areaCode = t3.areacode\n" +
                    "\tleft join \n" +
                    "\t(select t5.expertId,t4.name,t4.id from  t_subject  t4\n" +
                    "\tinner join t_expert_subject t5 on t4.id = t5.subjectId) t6\n" +
                    "\ton t1.id = t6.expertId\n" +
                    "\twhere t1.del_flg = 0 and t2.del_flg = 0 ");
            if (areaCode != null) {
                sql.append(" and t3.`areacode` LIKE '" + areaCode + "%'");
            }
            if (subjectId != null) {
                sql.append(" and  t6.id = " + subjectId);
            }

            return sql.toString();
        }

        public String getInterNetInfo(Map<String, Object> map) {
            //获取查询数据
            int userId = (int) map.get("userId");
            String roleCode = (String) map.get("roleCode");
            //创建sql
            StringBuffer sql = new StringBuffer();
            StringBuffer sql1 = new StringBuffer();
            StringBuffer sql2 = new StringBuffer();
            StringBuffer sql3 = new StringBuffer();
            StringBuffer sql4 = new StringBuffer();
            sql.append("select t1.*,t3.name rolename,t3.`code` rolecode,t4.areaname areaname,t3.id roleId ");
            if (roleCode.equals("ZMXC")) {
                sql1.append("\t,t5.town town,t5.village village,t5.url zmxcUrl , \n" +
                        "\t\t\t\t\tt5.createtime createtime ");
                sql3.append(" left JOIN t_countryside t5 on t5.userid=t1.id and t5.del_flg=0 ");
            } else if (roleCode.equals("QYYH")) {
                sql1.append(" ,t5.legalperson legalperson,(\n" +
                        "\t\tCASE t5.companytype\n" +
                        "\t\tWHEN 1 THEN\n" +
                        "\t\t\t'综合'\n" +
                        "\t\tWHEN 2 THEN\n" +
                        "\t\t\t'加工'\n" +
                        "\t\tWHEN 3 THEN\n" +
                        "\t\t\t'生产'\n" +
                        "\t\tWHEN 4 THEN\n" +
                        "\t\t\t'流通'\n" +
                        "\t\tEND\n" +
                        "\t) comTypeName,\tt5.cantact cantact,\n" +
                        "\tt5.tel qyyhTel,t5.fax fax,\n" +
                        "\tt5.logo logo,t5.companytype companytype,\n" +
                        "\tt5.url qyyhUrl,\tt5.createtime createtime ");
                sql3.append(" left JOIN t_company t5 on t5.userid = t1.id and t5.del_flg=0 ");
            } else if (roleCode.equals("EXPERT")) {
                sql1.append(" \t,t5.exinfoid exinfoid,t5.subid suejectid,t5.unit unit,\tt5.gender gender, \n" +
                        "\tt5.url zjUrl,t5.exCode exCode,t5.exName exName  ");
                sql3.append(" left JOIN (\n" +
                        "\tSELECT\n" +
                        "\t\ta.userid userid,\n" +
                        "\t\ta.id exinfoid,b.subjectId subid,\n" +
                        "\t\ta.unit unit,\n" +
                        "\t\ta.gender gender,\n" +
                        "\t\ta.url url,\n" +
                        "\t\tc. CODE exCode,\n" +
                        "\t\tc. NAME exName\n" +
                        "\tFROM\n" +
                        "\t\tt_expertinfo a\n" +
                        "\tINNER JOIN t_expert_subject b ON a.id = b.expertid\n" +
                        "\tAND a.del_flg = 0\n" +
                        "\tINNER JOIN t_subject c ON b.subjectId = c.id\n" +
                        "\tAND c.del_flg = 0\n" +
                        ") t5 ON t5.userid = t1.id");
            } else if (roleCode.equals("HZSYH")) {
                sql1.append(" ,t5.BusinessScope hzsBusinessScope,\n" +
                        "\tt5.AreaScale hzsAreaScale,\n" +
                        "\tt5.url hzsUrl,\n" +
                        "\tt5.AnnualProductionValue,\n" +
                        "\tt5.ProdOperaCount,\n" +
                        "\tt5.TechCount,\n" +
                        "\tt5.LeaderName,\n" +
                        "\tt5.LeaderPhone,\n" +
                        "\tt5.TechLeaderName,\n" +
                        "\tt5.TechLeaderPhone,\n" +
                        "\tt5.createtime createtime ");
                sql3.append(" left JOIN t_cooperative t5 ON t5.userid = t1.id\n" +
                        "AND t5.del_flg = 0 ");
            } else if (roleCode.equals("ZZDH")) {
                sql1.append(" ,t5.BusinessScope zzdhBusinessScope,\n" +
                        "\tt5.AreaScale zzdhAreaScale,\n" +
                        "\tt5.url zzdhUrl ");
                sql3.append(" LEFT JOIN t_grower t5 ON t5.userid = t1.id\n" +
                        "AND t5.del_flg = 0");
            } else if (roleCode.equals("GXSYH")) {
                sql1.append(" ,t5.url gxsUrl ");
                sql3.append(" left  JOIN t_suply_point t5 on t1.id=t5.userid and t5.del_flg=0 ");
            } else if (roleCode.equals("ZJYY")) {
                sql1.append(" ,t5.url zjyyUrl,\n" +
                        "t5.leadername,\n" +
                        "t5.lwaderphone ");
                sql3.append(" left  JOIN t_suply_yy t5 on t1.id=t5.userid and t5.del_flg=0 ");
            }
            sql2.append(" from t_user t1 join t_user_role t2 on t1.id = t2.userid  and t1.del_flg=0\n" +
                    "          LEFT JOIN t_role t3 on t3.id = t2.roleid\n" +
                    "          LEFT JOIN t_area t4 on t1.areacode = t4.areacode ");

            if (userId > 0 && roleCode != null && !"".equals(roleCode)) {
                sql4.append(" where t1.id='" + userId + "'");
            }
            return sql.toString() + sql1.toString() + sql2.toString() + sql3.toString() + sql4.toString();
        }

        /**
         * 更新角色信息
         **/
        public String updatePTYHbyId(Map<String, Object> map) {
            InterNetInfo interNetInfo = (InterNetInfo) map.get("interNetInfo");
            StringBuffer sql = new StringBuffer();
            sql.append("update t_user set ");
            if (interNetInfo.getUsername() != null) {
                sql.append(" userName = " + "'" + interNetInfo.getUsername() + "',");
            }
            if (interNetInfo.getShowName() != null) {
                sql.append(" showName = " + "'" + interNetInfo.getShowName() + "',");
            }
            if (interNetInfo.getLoginName() != null) {
                sql.append(" loginName = " + "'" + interNetInfo.getLoginName() + "',");
            }
            if (interNetInfo.getMobile() != null) {
                sql.append(" mobile = " + "'" + interNetInfo.getMobile() + "',");
            }
            if (interNetInfo.getAddress() != null) {
                sql.append(" address = " + "'" + interNetInfo.getAddress() + "',");
            }
            if (interNetInfo.getAreaCode() != null) {
                sql.append(" areaCode = " + "'" + interNetInfo.getAreaCode() + "',");
            }
            if (interNetInfo.getArea() != null) {
                sql.append(" areaCode = " + "'" + interNetInfo.getArea() + "',");
            }
            if (interNetInfo.getIntroduction() != null) {
                sql.append(" Introduction = " + "'" + interNetInfo.getIntroduction() + "',");
            }
            if (interNetInfo.getEmail() != null) {
                sql.append(" Email = " + "'" + interNetInfo.getEmail() + "',");
            }
            if (interNetInfo.getHeadImage() != null && !"".equals(interNetInfo.getHeadImage())) {
                sql.append(" HeadImage = " + "'" + interNetInfo.getHeadImage() + "',");
            }
            if (!"".equals(interNetInfo.getLatitude()) && interNetInfo.getLatitude() != null) {
                sql.append(" latitude = " + "'" + interNetInfo.getLatitude() + "',");
            }
            if (!"".equals(interNetInfo.getLongitude()) && interNetInfo.getLongitude() != null) {
                sql.append(" longitude = " + "'" + interNetInfo.getLongitude() + "',");
            }
            sql.append(" del_flg='" + interNetInfo.getDel_flg() + "'");
            sql.append(" WHERE id = '" + interNetInfo.getId() + "'");
            return sql.toString();
        }

        public String updateZZDHbyUserId(Map<String, Object> map) {

            InterNetInfo interNetInfo = (InterNetInfo) map.get("interNetInfo");
            StringBuffer sql = new StringBuffer();
            sql.append("update t_grower set ");
            if (!"".equals(interNetInfo.getZzdhBusinessScope()) && interNetInfo.getZzdhBusinessScope() != null) {
                sql.append(" businessscope= '" + interNetInfo.getZzdhBusinessScope() + "',");
            }
            if (!"".equals(interNetInfo.getZzdhAreaScale()) && interNetInfo.getZzdhAreaScale() != null) {
                sql.append(" areascale='" + interNetInfo.getZzdhAreaScale() + "',");
            }
            if (!"".equals(interNetInfo.getZzdhUrl()) && interNetInfo.getZzdhUrl() != null) {
                sql.append(" url='" + interNetInfo.getZzdhUrl() + "',");
            }

            sql.append(" del_flg='" + interNetInfo.getDel_flg() + "'");

            sql.append(" where userid='" + interNetInfo.getId() + "'");
            return sql.toString();
        }

        public String updateEXPERTbyUserId(Map<String, Object> map) {
            InterNetInfo interNetInfo = (InterNetInfo) map.get("interNetInfo");
            StringBuffer sql = new StringBuffer();

            sql.append("update t_expertinfo set ");
//            if (!"".equals(interNetInfo.getSuejectid()) && interNetInfo.getSuejectid() != null) {
//                sql.append(" suejectid='" + interNetInfo.getSuejectid() + "',");
//            }
            if (!"".equals(interNetInfo.getUnit()) && interNetInfo.getUnit() != null) {
                sql.append(" unit='" + interNetInfo.getUnit() + "',");
            }
            if (!"".equals(interNetInfo.getGender()) && interNetInfo.getGender() != null) {
                sql.append("gender='" + interNetInfo.getGender() + "',");
            }
            if (!"".equals(interNetInfo.getZjUrl()) && interNetInfo.getZjUrl() != null) {
                sql.append(" url='" + interNetInfo.getZjUrl() + "',");
            }

            sql.append(" del_flg='" + interNetInfo.getDel_flg() + "'");

            sql.append(" where userid='" + interNetInfo.getId() + "'");
            return sql.toString();
        }

        public String updateQYYHbyUserId(Map<String, Object> map) {

            InterNetInfo interNetInfo = (InterNetInfo) map.get("interNetInfo");
            StringBuffer sql = new StringBuffer();
            sql.append("update t_company set ");
            if (!"".equals(interNetInfo.getLegalperson()) && interNetInfo.getLegalperson() != null) {
                sql.append(" legalperson='" + interNetInfo.getLegalperson() + "',");
            }
            if (!"".equals(interNetInfo.getCantact()) && interNetInfo.getCantact() != null) {
                sql.append(" cantact='" + interNetInfo.getCantact() + "',");
            }
            if (!"".equals(interNetInfo.getQyyhTel()) && interNetInfo.getQyyhTel() != null) {
                sql.append(" tel='" + interNetInfo.getQyyhTel() + "',");
            }
            if (!"".equals(interNetInfo.getFax()) && interNetInfo.getFax() != null) {
                sql.append(" fax='" + interNetInfo.getFax() + "',");
            }
            if (!"".equals(interNetInfo.getLogo()) && interNetInfo.getLogo() != null) {
                sql.append(" logo='" + interNetInfo.getLogo() + "',");
            }
            if (!"".equals(interNetInfo.getCompanytype()) && interNetInfo.getCompanytype() != null) {
                sql.append(" companytype='" + interNetInfo.getCompanytype() + "',");
            }
            if (!"".equals(interNetInfo.getQyyhUrl()) && interNetInfo.getQyyhUrl() != null) {
                sql.append(" url='" + interNetInfo.getQyyhUrl() + "',");
            }

            sql.append(" del_flg='" + interNetInfo.getDel_flg() + "'");

            sql.append(" where userid='" + interNetInfo.getId() + "'");
            return sql.toString();
        }

        public String updateHZSYHbyUserId(Map<String, Object> map) {
            InterNetInfo interNetInfo = (InterNetInfo) map.get("interNetInfo");
            StringBuffer sql = new StringBuffer();
            sql.append("update t_cooperative set ");
            if (!"".equals(interNetInfo.getHzsBusinessScope()) && interNetInfo.getHzsBusinessScope() != null) {
                sql.append(" businessscope= '" + interNetInfo.getHzsBusinessScope() + "',");
            }
            if (!"".equals(interNetInfo.getHzsAreaScale()) && interNetInfo.getHzsAreaScale() != null) {
                sql.append(" areascale='" + interNetInfo.getHzsAreaScale() + "',");
            }
            if (!"".equals(interNetInfo.getAnnualProductionValue()) && interNetInfo.getAnnualProductionValue() != null) {
                sql.append(" AnnualProductionValue='" + interNetInfo.getAnnualProductionValue() + "',");
            }
            if (!"".equals(interNetInfo.getProdOperaCount()) && interNetInfo.getProdOperaCount() != null) {
                sql.append(" ProdOperaCount='" + interNetInfo.getProdOperaCount() + "',");
            }
            if (!"".equals(interNetInfo.getTechLeaderName()) && interNetInfo.getTechLeaderName() != null) {
                sql.append(" TechLeaderName='" + interNetInfo.getTechLeaderName() + "',");
            }
            if (!"".equals(interNetInfo.getTechCount()) && interNetInfo.getTechCount() != null) {
                sql.append(" TechCount='" + interNetInfo.getTechCount() + "',");
            }
            if (!"".equals(interNetInfo.getLeaderName()) && interNetInfo.getLeaderName() != null) {
                sql.append(" LeaderName='" + interNetInfo.getLeaderName() + "',");
            }
            if (!"".equals(interNetInfo.getLeaderPhone()) && interNetInfo.getLeaderPhone() != null) {
                sql.append(" LeaderPhone='" + interNetInfo.getLeaderPhone() + "',");
            }
            if (!"".equals(interNetInfo.getTechLeaderPhone()) && interNetInfo.getTechLeaderPhone() != null) {
                sql.append(" TechLeaderPhone='" + interNetInfo.getTechLeaderPhone() + "',");
            }
            if (!"".equals(interNetInfo.getHzsUrl()) && interNetInfo.getHzsUrl() != null) {
                sql.append(" url='" + interNetInfo.getHzsUrl() + "',");
            }

            sql.append(" del_flg='" + interNetInfo.getDel_flg() + "'");

            sql.append(" where userid='" + interNetInfo.getId() + "'");
            return sql.toString();
        }

        public String updateGXSbyUserId(Map<String, Object> map) {
            InterNetInfo interNetInfo = (InterNetInfo) map.get("interNetInfo");
            StringBuffer sql = new StringBuffer();

            sql.append("update t_suply_point set ");
            if (!"".equals(interNetInfo.getGxsUrl()) && interNetInfo.getGxsUrl() != null) {
                sql.append(" url='" + interNetInfo.getGxsUrl() + "',");
            }

            sql.append(" del_flg='" + interNetInfo.getDel_flg() + "'");

            sql.append(" where userid='" + interNetInfo.getId() + "'");
            return sql.toString();
        }

        public String updateZMXCbyUserId(Map<String, Object> map) {
            InterNetInfo interNetInfo = (InterNetInfo) map.get("interNetInfo");
            StringBuffer sql = new StringBuffer();

            sql.append("update t_countryside set ");
            if (!"".equals(interNetInfo.getCounty()) && interNetInfo.getCounty() != null) {
                sql.append(" county='" + interNetInfo.getCounty() + "',");
            }
            if (!"".equals(interNetInfo.getTown()) && interNetInfo.getTown() != null) {
                sql.append(" town='" + interNetInfo.getTown() + "',");
            }
            if (!"".equals(interNetInfo.getVillage()) && interNetInfo.getVillage() != null) {
                sql.append(" village='" + interNetInfo.getVillage() + "'");
            }
            if (!"".equals(interNetInfo.getZmxcUrl()) && interNetInfo.getZmxcUrl() != null) {
                sql.append(" url='" + interNetInfo.getZmxcUrl() + "',");
            }

            sql.append(" del_flg='" + interNetInfo.getDel_flg() + "'");

            sql.append(" where userid='" + interNetInfo.getId() + "'");
            return sql.toString();
        }

        public String updateZJYYbyUserId(Map<String, Object> map) {
            InterNetInfo interNetInfo = (InterNetInfo) map.get("interNetInfo");
            StringBuffer sql = new StringBuffer();

            sql.append("update t_suply_yy set ");
            if (!"".equals(interNetInfo.getYyName()) && interNetInfo.getYyName() != null) {
                sql.append(" name='" + interNetInfo.getYyName() + "',");
            }
            if (!"".equals(interNetInfo.getZjyyTel()) && interNetInfo.getZjyyTel() != null) {
                sql.append(" tel='" + interNetInfo.getZjyyTel() + "',");
            }
            if (!"".equals(interNetInfo.getZjyyUrl()) && interNetInfo.getZjyyUrl() != null) {
                sql.append(" url='" + interNetInfo.getZjyyUrl() + "',");
            }

            sql.append(" del_flg='" + interNetInfo.getDel_flg() + "'");

            sql.append(" where userid='" + interNetInfo.getId() + "'");

            return sql.toString();
        }

        /****
         * 插入角色信息数据
         * **/
        public String insertEXPERT(Map<String, Object> map) {
            InterNetInfo interNetInfo = (InterNetInfo) map.get("interNetInfo");
            StringBuffer sql = new StringBuffer();
            sql.append("insert into t_expertinfo(userid,unit,gender,url,del_flg) ");
            sql.append(" values(");
            sql.append("'").append(interNetInfo.getId()).append("'").append(",");
            sql.append("'").append(interNetInfo.getUnit()).append("'").append(",");
            sql.append("'").append(interNetInfo.getGender()).append("'").append(",");
            sql.append("'").append(interNetInfo.getZjUrl()).append("'").append(",");
            sql.append("'").append(0).append("'").append(");");
            return sql.toString();
        }

        public String insertQYYH(Map<String, Object> map) {
            InterNetInfo interNetInfo = (InterNetInfo) map.get("interNetInfo");
            StringBuffer sql = new StringBuffer();
            sql.append("insert into t_company(userid,legalperson,cantact,tel,fax,url,logo,companytype,del_flg) ");
            sql.append(" values(");
            sql.append("'").append(interNetInfo.getId()).append("'").append(",");
            sql.append("'").append(interNetInfo.getLegalperson()).append("'").append(",");
            sql.append("'").append(interNetInfo.getCantact()).append("'").append(",");
            sql.append("'").append(interNetInfo.getQyyhTel()).append("'").append(",");
            sql.append("'").append(interNetInfo.getFax()).append("'").append(",");
            sql.append("'").append(interNetInfo.getQyyhUrl()).append("'").append(",");
            sql.append("'").append(interNetInfo.getLogo()).append("'").append(",");
            sql.append("'").append(interNetInfo.getCompanytype()).append("'").append(",");
            sql.append("'").append(0).append("'").append(");");
            return sql.toString();
        }

        public String insertHZSYH(Map<String, Object> map) {
            InterNetInfo interNetInfo = (InterNetInfo) map.get("interNetInfo");
            StringBuffer sql = new StringBuffer();
            sql.append("insert into t_cooperative(userid,BusinessScope,AreaScale,AnnualProductionValue,ProdOperaCount,TechCount,LeaderName,LeaderPhone," +
                    "TechLeaderName,TechLeaderPhone,url,del_flg) ");
            sql.append(" values(");
            sql.append("'").append(interNetInfo.getId()).append("'").append(",");
            sql.append("'").append(interNetInfo.getHzsBusinessScope()).append("'").append(",");
            sql.append("'").append(interNetInfo.getHzsAreaScale()).append("'").append(",");
            sql.append("'").append(interNetInfo.getAnnualProductionValue()).append("'").append(",");
            sql.append("'").append(interNetInfo.getProdOperaCount()).append("'").append(",");
            sql.append("'").append(interNetInfo.getTechCount()).append("'").append(",");
            sql.append("'").append(interNetInfo.getLeaderName()).append("'").append(",");
            sql.append("'").append(interNetInfo.getLeaderPhone()).append("'").append(",");
            sql.append("'").append(interNetInfo.getTechLeaderName()).append("'").append(",");
            sql.append("'").append(interNetInfo.getTechLeaderPhone()).append("'").append(",");
            sql.append("'").append(interNetInfo.getHzsUrl()).append("'").append(",");
            sql.append("'").append(0).append("'").append(");");
            return sql.toString();
        }

        public String insertZZDH(Map<String, Object> map) {
            InterNetInfo interNetInfo = (InterNetInfo) map.get("interNetInfo");
            StringBuffer sql = new StringBuffer();
            sql.append("insert into t_grower(userid,BusinessScope,AreaScale,url,del_flg) ");
            sql.append(" values(");
            sql.append("'").append(interNetInfo.getId()).append("'").append(",");
            sql.append("'").append(interNetInfo.getZzdhBusinessScope()).append("'").append(",");
            sql.append("'").append(interNetInfo.getZzdhAreaScale()).append("'").append(",");
            sql.append("'").append(interNetInfo.getZzdhUrl()).append("'").append(",");
            sql.append("'").append(0).append("'").append(");");
            return sql.toString();
        }

        public String insertZMXC(Map<String, Object> map) {
            InterNetInfo interNetInfo = (InterNetInfo) map.get("interNetInfo");
            StringBuffer sql = new StringBuffer();
            sql.append("insert into t_countryside(userid,county,village,town,url,del_flg) ");
            sql.append(" values(");
            sql.append("'").append(interNetInfo.getId()).append("'").append(",");
            sql.append("'").append(interNetInfo.getCounty()).append("'").append(",");
            sql.append("'").append(interNetInfo.getVillage()).append("'").append(",");
            sql.append("'").append(interNetInfo.getTown()).append("'").append(",");
            sql.append("'").append(interNetInfo.getZmxcUrl()).append("'").append(",");
            sql.append("'").append(0).append("'").append(");");
            return sql.toString();
        }

        public String insertGXS(Map<String, Object> map) {
            InterNetInfo interNetInfo = (InterNetInfo) map.get("interNetInfo");
            StringBuffer sql = new StringBuffer();
            sql.append("insert into t_suply_point(userid,url,del_flg) ");
            sql.append(" values(");
            sql.append("'").append(interNetInfo.getId()).append("'").append(",");
            sql.append("'").append(interNetInfo.getGxsUrl()).append("'").append(",");
            sql.append("'").append(0).append("'").append(");");

            return sql.toString();
        }

        public String insertZJYY(Map<String, Object> map) {
            InterNetInfo interNetInfo = (InterNetInfo) map.get("interNetInfo");
            StringBuffer sql = new StringBuffer();
            sql.append("insert into t_suply_yy(userid,tel,url,del_flg) ");
            sql.append(" values(");
            sql.append("'").append(interNetInfo.getId()).append("'").append(",");
            sql.append("'").append(interNetInfo.getZjyyTel()).append("'").append(",");
            sql.append("'").append(interNetInfo.getZjyyUrl()).append("'").append(",");
            sql.append("'").append(0).append("'").append(");");
            return sql.toString();
        }
    }


}
